package Operation;

import demo1.Book;
import demo1.BookList;

import java.util.Scanner;

public class addOperation implements IOPeration {
    public void work(BookList bookList){
        System.out.println("添加图书！");
        System.out.println("请输入书名！");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();
        System.out.println("请输入作者！");
        String author = scanner.nextLine();
        System.out.println("请输入价格！");
        int price = scanner.nextInt();
        scanner.nextLine();
        System.out.println("请输入类型！");
        String type = scanner.nextLine();

        Book book = new Book(name,author,price,type);

        int currentSize = bookList.getUsedSize();
        for (int i = 0; i < currentSize; i++) {
            Book book2 = bookList.getBook(i);
            if(book2.getName().equals(name)){
                System.out.println("书架上已经有这本书了！");
                return;
            }
        }
        bookList.setBook(currentSize,book);
        bookList.setUsedSize(currentSize+1);
    }
}
